package com.cn.zpark;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @PackageName: com.cn.zpark
 * @ClassName: CookieDemo02
 * @Description:
 * @author: RZS
 * @date: 2022/4/13  11:08
 */
@WebServlet("/cook2")
public class CookieDemo02 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 获取cookie信息
        Cookie[] cookies = request.getCookies();
        // 循环遍历cookie信息
        for (Cookie cookie : cookies) {
            // 获取cookie名字
            String name = cookie.getName();
            // 获取cookie的值
            String value = cookie.getValue();
            System.out.println(name + " : " + value);

            System.out.println(cookie.getMaxAge());
        }
    }
}
